<?php

namespace app\admin\controller\purchase;

use app\common\controller\Backend;
use app\admin\model\Order as OrderModel;
use think\db\exception\PDOException;
use think\exception\ValidateException;
use think\facade\Config;
use think\facade\Db;
use Exception;

/*
 * 合并订单
 */
class Merge extends Backend {


    /**
     * 撤回出货状态
     */
    public function withdrawShipmentStatus(): void{
        $params = $this->request->get();
        $modify_record = Db::name('purchase_order_modify')->where(['id' => $params['order_id']])->find();
        if(!$modify_record){
            $this->error('状态未曾更新过');
        }
    }

    /**
     * 更新出货状态
     */
    public function saveShipmentStatus(): void{
        $params = $this->request->get();

        $order = Db::name('order')->where(['id' => $params['order_id']])->find();

        $insert = [
            'order_id' => $order['id'],
            'before_change_shipment_status' => $order['shipment_status'],
            'after_change_shipment_status' => $params['shipment_status'],
            'create_time' => $this->timestamp
        ];
        Db::name('purchase_order_modify')->insert($insert); // 写入修改记录

        $update = [
            'shipment_status_update_time' => $this->timestamp,
            'shipment_status' => $params['shipment_status']
        ];
        $result = Db::name('order')->where(['id' => $params['order_id']])->update($update); // 修改订单数据
        if($result){
            $this->success();
        }else{
            $this->error();
        }
        print_r($params);die;
    }


}